package com.koo.modules.cx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.cx.dao.CxAttachFileDao;
import com.koo.modules.cx.entity.CxAttachFileEntity;
import com.koo.modules.cx.service.CxAttachFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
public class CxAttachFileServiceImpl extends ServiceImpl<CxAttachFileDao, CxAttachFileEntity> implements CxAttachFileService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<CxAttachFileEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(MyStrUtil.isNotEmpty(key), CxAttachFileEntity::getFileId, key)
                .or().eq(MyStrUtil.isNotEmpty(key), CxAttachFileEntity::getFilePath, key);

        IPage<CxAttachFileEntity> page = this.page(
                new Query<CxAttachFileEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}